package dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class ConnectDao {
	public Connection conn = null;
	public Statement stat = null;
	String url =  "jdbc:sqlserver://localhost:1433;" +
            "databaseName=hotel2;user=sa;password=yang2456064131;";
	public ConnectDao(){
		try{
			Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
			conn = DriverManager.getConnection(url);
			stat = conn.createStatement();
		}catch(SQLException e){
			e.printStackTrace();
			System.out.println(e.getMessage());
		}catch(ClassNotFoundException e){
			e.printStackTrace();
			System.out.println(e.getMessage());
		}
	}
	public void closeConnect(){
		if(stat!=null){
			try {
				stat.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		if(conn!=null){
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}
	
	public Connection getConn() {
		return conn;
	}
	public void setConn(Connection conn) {
		this.conn = conn;
	}
	public Statement getStat() {
		return stat;
	}
	public void setStat(Statement stat) {
		this.stat = stat;
	}
	public String getUrl() {
		return url;
	}
	public void setUrl(String url) {
		this.url = url;
	}
	
}
